#!/usr/bin/env php
<?php

# A worker that tracks URLs that have been inserted.

$urls = array();
$worker = new GearmanWorker();
$worker->addServer('127.0.0.1', 4730);
$worker->addFunction('insert_url', 'insert_url_callback');
while (@$worker->work());

function insert_url_callback($job)
{
  $url = $job->workload();

  if (in_array($url, $GLOBALS['urls']))
    return;

  print "$url\n";

  array_push($GLOBALS['urls'], $url);

  $client = new GearmanClient();
  $client->addServer('127.0.0.1', 4730);
  $client->doBackground('fetch_url', $url);
}

?>
